package org.mobile.validators;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

public class FloatValidator implements Validator {
	@Override
	public void validate(FacesContext arg0, UIComponent arg1, Object value)
			throws ValidatorException {
			String fieldValue= (String)value;
			Pattern pattern;
			pattern= Pattern.compile("^[0-9]*[.][0-9]+$");
			Matcher matcher= pattern.matcher(fieldValue);
			if(!matcher.matches()){
				FacesMessage message= new FacesMessage("Pole może zawierać tylko liczby w podanym formacie np 800.600");
				throw new ValidatorException(message);
			}
		
	}
}
